﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using RTGS.Library.Entities.Rtgs;
using RTGS.Library.DataAccess.Rtgs;
using System.Configuration;

namespace RTGS.Web.form.rtgs
{

public partial class form_rtgs_stp_userform : BasePage
    {
        private string id = string.Empty;

        private   stpUserRepo tAccountDal = new stpUserRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        private stpGroupRepo groupRepo = new stpGroupRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            List<stpGroup> list = groupRepo.GetList();

            ddlUserGroup.Items.Clear();
            foreach (stpGroup data in list)
            {
                ddlUserGroup.Items.Add(new ListItem(data.groupname,data.groupid.ToString()));
            }

            //ddlUserGroup.Items.Insert(0, new ListItem("---pilih data--", string.Empty));

            rowpassword.Visible = true;


            if (Request.Params["id"] != null)
            {
                id = Convert.ToString(Request.Params["id"]);
            }

            if (!Page.IsPostBack)
            {
                if (id.Trim().Length > 0) // Edit an existing item
                {
                    stpUser obj = tAccountDal.GetById(id);
                    if (obj != null)
                    {
                        hfID.Value = id.ToString();
                        txtUserName.Text = obj.username;
                        ddlUserGroup.Items.FindByValue(obj.usergroupid.ToString().Trim()).Selected = true;
                        txtUserMax.Text = obj.usermaxAmount.ToString();
                        rowpassword.Visible = false;
                        //txtStatus.Text = obj.status;
                        //txtAccountName.Text = obj.acntname;
                        
                    }
                }
            }

        }

    }
}
